package com.fw.system.web.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fw.system.web.model.form.WechatForm;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * <p>
 * 客户端用户表
 * </p>
 *
 * @author ${author}
 * @since 2023-03-28
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="TbUser对象", description="客户端用户表")
@NoArgsConstructor
public class TbUser extends Model<TbUser> {

    private static final long serialVersionUID = 1L;

    public TbUser (WechatForm wechatForm, String userId){
        createD(userId);
        this.id = userId;
        this.openId = wechatForm.getOpenId();
        this.imgUrl = wechatForm.getAvatarUrl();
        this.nickName = wechatForm.getNickName();

    }
    @TableId("id")
    private String id;

    @TableField("open_id")
    private String openId;

    @ApiModelProperty(value = "微信昵称")
    @TableField("nick_name")
    private String nickName;

    @ApiModelProperty(value = "微信头像")
    @TableField("img_url")
    private String imgUrl;

    @ApiModelProperty(value = "手机号")
    @TableField("phone_number")
    private String phoneNumber;

    @ApiModelProperty(value = "1已加入城市战队 0未加入")
    @TableField("is_battalion")
    private Integer isBattalion;

    @ApiModelProperty(value = "全国排名")
    @TableField("country_sort")
    private Integer countrySort;

    @ApiModelProperty(value = "所属战队ID")
    @TableField("city_code")
    private String cityCode;

    @ApiModelProperty(value = "邀请码")
    @TableField("invite_code")
    private String inviteCode;

    @ApiModelProperty(value = "创建时间")
    @TableField("create_time")
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @ApiModelProperty(value = "修改时间")
    @TableField("update_time")
    private LocalDateTime updateTime;

    @ApiModelProperty(value = "创建人")
    @TableField("create_by")
    private String createBy;

    @ApiModelProperty(value = "修改人")
    @TableField("update_by")
    private String updateBy;

    @ApiModelProperty(value = "0禁用 1可用")
    @TableField("is_state")
    private Integer isState;

    @ApiModelProperty(value = "是否获得城市勋章 0未获取 1获取")
    @TableField("is_medal")
    private Integer isMedal;

    @ApiModelProperty(value = "当前有效的微信步数")
    @TableField("wechat_fool")
    private Integer wechatFool;

    @ApiModelProperty(value = "当前累计的微信步数")
    @TableField("count_fool")
    private Integer countFool;

    @ApiModelProperty(value = "炸弹数量")
    @TableField("bomb")
    private Integer bomb;

    @ApiModelProperty(value = "护盾数量")
    @TableField("shield")
    private Integer shield;

    @ApiModelProperty(value = "积分数值")
    @TableField("integral")
    private Integer integral;

    @ApiModelProperty(value = "当前解锁城市个数")
    @TableField("now_city_count")
    private Integer nowCityCount;
    public void createD(String createId){
        this.createBy = createId;
        this.createTime = LocalDateTime.now();
        if (this.createTime != null)
            this.updateTime = this.createTime;
        this.updateBy = this.createBy;

    }

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

}
